package com.zk.mylib.ui.activity

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.Gravity
import android.view.View
import android.widget.Button
import androidx.drawerlayout.widget.DrawerLayout
import androidx.drawerlayout.widget.DrawerLayout.DrawerListener
import com.gc.logger.LogUtils

import com.zk.mylib.R

/**
 * 抽屉
 */
class DrawerLayoutActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_ui_drawerlayout)
        var mDrawerlayout = findViewById<DrawerLayout>(R.id.drawerlayout)
        mDrawerlayout.setDrawerTitle(Gravity.LEFT,"DrawerLayoutActivity")
        mDrawerlayout.addDrawerListener(object :DrawerListener{
            override fun onDrawerSlide(drawerView: View, slideOffset: Float) {
                LogUtils.e("DrawerLayout","onDrawerSlide slideOffset=$slideOffset")
            }

            override fun onDrawerOpened(drawerView: View) {
                LogUtils.e("DrawerLayout","onDrawerOpened leftopen=${mDrawerlayout.isDrawerOpen(Gravity.LEFT)}  rightopen=${mDrawerlayout.isDrawerOpen(Gravity.RIGHT)}")
            }

            override fun onDrawerClosed(drawerView: View) {
                LogUtils.e("DrawerLayout","onDrawerClosed leftopen=${mDrawerlayout.isDrawerOpen(Gravity.LEFT)}  rightopen=${mDrawerlayout.isDrawerOpen(Gravity.RIGHT)}")
            }

            override fun onDrawerStateChanged(newState: Int) {
                LogUtils.e("DrawerLayout","onDrawerStateChanged newState=$newState")
                LogUtils.e("DrawerLayout","onDrawerStateChanged leftopen=${mDrawerlayout.isDrawerOpen(Gravity.LEFT)}  rightopen=${mDrawerlayout.isDrawerOpen(Gravity.RIGHT)}")
            }

        })

        var leftButtonOpen = findViewById<Button>(R.id.btn_open_left)
        leftButtonOpen.setOnClickListener { mDrawerlayout.openDrawer(Gravity.LEFT) }

        var rightButtonOpen = findViewById<Button>(R.id.btn_open_right)
        rightButtonOpen.setOnClickListener { mDrawerlayout.openDrawer(Gravity.RIGHT) }

    }
}